var container = document.getElementById("container");
container.addEventListener("touchmove" , function(event){
	event.preventDefault();
	})


String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");

}

function checkPhone(phone){ 
	if(!(/^1[3|4|5|6|7|8|9]\d{9}$/.test(phone))){ 
	return false; 
	}else{
		return true;
		} 
}




function setCss3 (obj,attrObj) {
   for (var i in attrObj) {
     var newi=i;
	 if(newi.indexOf("-")>0){
	   var num=newi.indexOf("-");
	   newi=newi.replace(newi.substr(num,2),newi.substr(num+1,1).toUpperCase());
	 }
	 obj.style[newi]=attrObj[i];
	 newi=newi.replace(newi.charAt(0),newi.charAt(0).toUpperCase());
	 obj.style["webkit"+newi]=attrObj[i];
	 obj.style["moz"+newi]=attrObj[i];
	 obj.style["o"+newi]=attrObj[i];
	 obj.style["ms"+newi]=attrObj[i];
   }
  }

$(function(){
	//icom.alert("123")
	
	/*$(".content").on("swipeleft" , function(){
		console.log("swipeleft")
		})*/
	
	/*var wh = $(window).height();
	var ww = $(window).width();
	var floor=[];
	var top=0;
	for(var i=0;i<6;i++){
		var scale=(i/6)+0.7;
		if(i>0){
			top = top+80*scale
		}
		createFloor({
			top:top,
			scale:scale,
			step:4,
			n:1
		})
	}
	
	
	
	function createFloor(options){
		var div = document.createElement("DIV");
		var className = "floor";
		div.className="flooritem "+className;
		div.style.top=options.top+"px";
		div.style.transform="translate3d(-50% , 0 , 0)scale("+options.scale+","+options.scale+")";
		div.step=options.step; //div.step=div.step+2
		div.n=options.n;
		div.top=options.top;
		div.scale=options.scale; // div.scale=div.scale+0.2 
		var tclassName="."+className
		$(".floorWrapper").append(div);
		floor.push(div)
	}*/
	
	
	
	
	
	
	var wh = $(window).height();
	var ww = $(window).width();
	var floor=[]; // 地板数组
	var lock=false; // 控制播放暂停
	var content = document.getElementById("content")
	
	var img="<img src='images/fc.png' class='fc' />"
	
	
	for(var i=0;i<6;i++){
		
		var top = i*100+i*20;
		
		
		createFloor({
			top:top
		})
	}
	
	
	
	
	
	
	
	
	function createFloor(options){
		var div = document.createElement("DIV");
		var className = "floor";
		div.className="flooritem "+className;
		div.top=options.top;
		div.style.top=options.top+"px";
		var tclassName="."+className
		$(".floorWrapper").append(div);
		
		
		var img = document.createElement("img");
		img.className="zaw";
		img.src="images/fc.png";
		div.appendChild(img);
		
		
		floor.push(div)
	}
	
	
	function moveFloor(){
		for(var i=0;i<floor.length;i++){
			floor[i].top = floor[i].top+3
			floor[i].style.top=floor[i].top+"px";
			if(floor[i].top>=720){
				floor[i].top = 0;
				floor[i].style.top="0px";
				
			}
		}
	}
	var animal = $(".animal")
	//var animalTop = wh-130;
	//animal.css({top:animalTop})
	var atop = 0;
	var n=0;
	var astep=6; //4  118  4
	
	var sx=0;
	var mx=0;
	var aleft=0;
	
	function animalAnim(){
		
		atop=atop+astep;
		if(atop>118){
			
			astep=-6
		}else if(atop<=0){
			
			astep=6
		}
		setCss3(animal[0],{"transform":"translate3d(-50%,-"+atop+"px,0)"})
		
	}
	
	
	
	/* setInterval(function(){
		moveFloor()
		animalAnim()
	},15) */
	window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
	
	
	
	//animate();
	
	function animate(){
		if(!lock){
			moveFloor();
		}
		animalAnim()
		requestAnimationFrame(animate);
	}
	
	
	addEventfn()
	function addEventfn(){
		content.addEventListener("touchstart" , startfn , false)
		content.addEventListener("touchmove" , movefn , false)
		content.addEventListener("touchend" , endfn , false)
	}
	
	function startfn(e){
		aleft = animal[0].offsetLeft;
		sx = e.touches[0].pageX;
		mx = sx;
	}
	function movefn(e){

		mx = e.touches[0].pageX;
		var mleft = aleft+(mx-sx);
		if(mleft<0 || mleft>ww){
			return;
		}
		animal.css({left:mleft})
	}
	function endfn(e){
		
	}
	
	
	
	
	
	})








